import React from 'react';
import Title from '../_/title';
import Table from './table';
import Editor from './editor';
import _name, {_title} from './dev';

export default class Index extends React.Component {
    state = {};
    onState = (flag, ...args) => {
        switch (flag) {
        case 'save':
            this.setState({showEditor: false});
            break;
        case 'cancel':
            this.setState({showEditor: false});
            break;
        case 'new':
            this.setState({showEditor: true, dataEdit: {}});
            break;
        case 'edit':
            this.setState({showEditor: true, dataEdit: args[0]});
            break;
        case 'query':
            const {keyword = ''} = args[0];
            this.setState({query: keyword});
            break;
        }
    }

    render() {
        return (
            <div className="w100" id={_name}>
                <Title onState={this.onState} title={`${_title}管理`} btn2Text="新增"/>
                <Table onState={this.onState}/>
                <Editor
                    onState={this.onState} title={_title} visible={this.state.showEditor}
                    dataEdit={this.state.dataEdit}
                />
                <div className="div"/>
            </div>
        );
    }
}
